#include "types.h"
#include "param.h"
#include "memlayout.h"
#include "riscv.h"
#include "spinlock.h"
#include "cow.h"
#include "defs.h"


void ins_r_cnt(uint64 pa) {
    if (pa < KERNBASE) {
        return ;
    } 
    pa = (pa - KERNBASE) >> 12;
    acquire(&cows[pa].lock);
    ++cows[pa].r_cnt;
    release(&cows[pa].lock);
}

uint8 dec_r_cnt(uint64 pa) {
    uint8 rcnt = 0;
    if (pa < KERNBASE) {
        return 0;
    }

    pa = (pa - KERNBASE) >> 12;
    acquire(&cows[pa].lock);
    rcnt = --cows[pa].r_cnt;
    release(&cows[pa].lock);
    return rcnt;
}